<?php
include_once("../../php/include_all.php");
session_start();
?>
<div class="row-fluid">
	<div class="span12">
		<h3 class="page-title">
            <b>Data Indikator</b>
        </h3>
		       <a href="#modalwin" data-toggle="modal" class="btn btn-primary btn-tambah">Tambah Data</a>
        <div id="modalwin" class="modal hide fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

             <header class="modal-header">
			<a href="#" class="close geo-clear" data-dismiss="modal">x</a>
                <h3>Data Indikator</h3>
            </header>
            <div class="modal-body">
              <form id="form_indikator"  class="form-horizontal">
					<input type="hidden" name="act" value="indikator_action">
					<input type="hidden" id="id_indikator" name="id_indikator" value="0">
					<div class="control-group">
                        <label class="control-label">Jenis Pelayanan</label>
                        <div class="controls">
                            <select name="id_pelayanan" id="id_pelayanan">
								<option id="id_pel" value="0">Pilih salah satu</option>
								<?php
									$pel = get_datas("SELECT * FROM spm_jenis_pelayanan p,spm_skpd s where s.id_skpd = ".$_SESSION['_id']." AND s.id_bidang=p.id_bidang order by p.id_pelayanan");
									foreach($pel as $pel){
								?>
									<option value=<?php echo $pel['id_pelayanan']; ?>><?php echo $pel['nama_pelayanan']; ?></option>
								<?php
								}
								?>
							</select>
                        </div>
					</div>
					<div class="control-group">
                        <label class="control-label">Kode Indikator</label>
                        <div class="controls">
                            <input type="text" id="kode_indikator" name="kode_indikator" class="input-xlarge" readonly />
                        </div>
					</div>
					<div class="control-group">
                        <label class="control-label">Nama Indikator</label>
                        <div class="controls">
                            <input type="text" id="nama_indikator" name="nama_indikator" class="input-xlarge" />
                        </div>
					</div>
					<div class="control-group">
                        <label class="control-label">Batas Waktu Capaian</label>
                        <div class="controls">
                            <input type="text" id="tahun_batas_capaian" name="tahun_batas_capaian" class="input-small" />
                        </div>
					</div>
					<div class="control-group">
                        <label class="control-label">Target Capaian</label>
                        <div class="controls">
                            <input type="text" id="nilai_spm" name="nilai_spm" class="input-small" /> %
                        </div>
					</div>
					<div class="control-group">
                        <label class="control-label">Nama Pembilang</label>
                        <div class="controls">
                            <input type="text" id="nama_kompind_pem" name="nama_kompind_pem" class="input-xlarge" />
                        </div>
					</div>
					<div class="control-group">
                        <label class="control-label">Nama Penyebut</label>
                        <div class="controls">
                            <input type="text" id="nama_kompind_pen" name="nama_kompind_pen" class="input-xlarge" />
                        </div>
					</div>
                        <a class="btn btn-primary bt-simpan-indikator"><div id="loader" style="margin-top:2px"></div>&nbsp;Save</a>
                                <span id="result"></span>
				</form>
            </div>
		</div>
	</div>
	</div>
	</br>
	<div class="row-fluid">
        <div class="span12">
			<div class="widget" style="">
                <div class="widget-title">
                    <h4><i class="icon-reorder"></i>Tabel Indikator</h4>
                    <span class="tools">
                        <a href="javascript:;" class="icon-chevron-down"></a>
                    </span>
                </div>
				<div class="widget-body">
                    <table class="table table-striped table-bordered" id="sample_1">
                    <thead>
                        <tr>
                            <th class="hidden-phone" style="width:20px; text-align:center;">No</th>
                            <th style="text-align:center;">Jenis Pelayanan</th>
                            <th style="text-align:center;">Nama Indikator</th>
                            <th style="text-align:center;">Batas Capaian</th>
                            <th style="text-align:center;">Target Capaian</th>
                            <th style="text-align:center;">Nama Pembilang</th>
                            <th style="text-align:center;">Nama Penyebut</th>
							<th style="text-align:center;">Edit</th>
                        </tr>
                    </thead>
                    <tbody id="tb-indikator">
					<?php 
					$no=1;
					$ind = get_datas("SELECT * from spm_indikator i,spm_jenis_pelayanan j where i.id_skpd=".$_SESSION['_id']." AND i.id_pelayanan=j.id_pelayanan order by i.id_pelayanan");
					foreach ($ind as $ind){
					?>
						<tr>
							<td><?php echo $no ?></td>
							<td> <?php echo $ind['nama_pelayanan'];?></td>
							<td><?php echo $ind['nama_indikator']?></td>
							<td><?php echo $ind['tahun_batas_capaian']?></td>
							<td><?php echo $ind['nilai_spm']?></td>
							<td><?php echo $ind['nama_kompind_pem']?></td>
							<td><?php echo $ind['nama_kompind_pen']?></td>
							<td style="width:200px; text-align:center;">
							<a class="btn btn-danger bt-delete-indikator" name="<?php echo $ind['id_indikator']; ?>">Delete</a>
                                <a  href="#modalwin" data-toggle="modal"  class="btn btn-info bt-edit-indikator" name="<?php echo $ind['id_indikator']; ?>">Edit</a>
							</td>
						</tr>
						<?php 
						$no++;
						}
						?>
					</tbody>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript" src="../assets/data-tables/jquery.dataTables.js"></script>
<script type="text/javascript" src="../assets/data-tables/DT_bootstrap.js"></script>
<script>
    jQuery(document).ready(function() {       
         // initiate layout and plugins
        App.init();
    });
</script>

<script>
var urls = 'master_indikator/indikator_action.php';

$('#id_pelayanan').change(function(){
    source ="master_indikator/id.php?idp="+this.value;
    var coba=$.get(source);
    coba.done(function(res){          
        document.getElementById('kode_indikator').value=res;	
    })
});
	
$('.bt-simpan-indikator').click(function(){
	var btn  = $(this);
	var load = $('#loader');
	var rslt = $('#result');
	load.addClass('spinner pull-left');
	btn.removeClass('btn-primary').addClass('btn-info');
	
	var form = $('#form_indikator');
	var data = form.serializeArray();
	var post = $.post(urls,data);
	post.done(function(res){
		var result = res.split('__');
		//   0      1     2
		//success__id__(isi tbody)tr
		if(result.length==3){
			if(result[0]=='success'){
				rslt.html('<font color="green">tersimpan...</font>');
				setTimeout(function(){
					rslt.html('');
				},1500);
				var tbody = $('#tb-indikator');
				tbody.html(result[2]);
				document.getElementById('form_indikator').reset();
				 //$('#thn_angg').val(' ');
				init();
			}else{
				rslt.html('<font color="red">'+res+'</font>');
			}
		}else{
			rslt.html('<font color="red">'+res+'</font>');
		}
		load.removeClass();
		btn.removeClass('btn-info').addClass('btn-primary');
	});
});
	
function init(){
$('.bt-delete-indikator').click(function(){
			var btn = $(this);
			var pid = this.name;
			var load = $(this);
			bootbox.confirm("Anda akan menghapus data ini?", function(result) {
                if(result==true){
                    if(pid!=0){
                        var post = $.post(urls,{act:"del_indikator",id_indikator:pid});
                        post.done(function(res){
                            var hasil = res.split('__');
						if(hasil.length==2){
							if(hasil[0] == 'success'){
								var tbody = $('#tb-indikator');
								tbody.html(hasil[1]);
								init();
									}
								}
                        });
                        load.html('Delete');
                    }
                }else{
                    load.html('Delete');
                }
            });
		});
	
	$('.bt-edit-indikator').click(function(){
		var id_indikator = this.name;
		var form = $('#form_indikator');
		var post = $.post(urls,{act:'edit_indikator',id_indikator:id_indikator});
		post.done(function(res){
			var value = res.split('__');
			$('#id_indikator').val(value[0]);
                form.find('select[name="id_pelayanan"]').val(value[1]); 
				form.find('input[name=kode_indikator]').val(value[2]);
                form.find('input[name="nama_indikator"]').val(value[3]);
                form.find('input[name="tahun_batas_capaian"]').val(value[4]);
				form.find('input[name="nama_kompind_pem"]').val(value[4]);
				form.find('input[name="nama_kompind_pen"]').val(value[5]);
				form.find('input[name="tahun_batas_capaian"]').val(value[6]);
				form.find('input[name="nilai_spm"]').val(value[7]);
		});
	});
}

$('.geo-clear').click(function(){
	$('#id_indikator').val(0);
	document.getElementById('form_indikator').reset();
});
init();
</script>